﻿
@page
@model AdminUI.Pages.BaseData.TenantModel
@{
    var F = Html.F();
}

@section body {
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" EnableMultiSelect="false" AllowSorting="true" AllowPaging="true" IsDatabasePaging="true"
                    DataIDField="TenantID" DataTextField="TenantName" SortingToolTip="true" SortingCancel="true" PageSize="@ViewBag.PageSize" RecordCount="@ViewBag.Total" DataSource="@ViewBag.DataSource" 
                    OnSort="@Url.Handler("Grid_DoAction")" OnSortFields="Panel1" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Panel1" FixedRowHeight="true" RowHeight="60">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnChangeEnableUsers" IconAlign="Left" EnableDefaultState="false" IconFont="_Tag" Text="状态">
                                <Menu>
                                    <f:MenuButton ID="btnEnableUsers" Text="启用" OnClientClick="onEnableClick();"></f:MenuButton>
                                    <f:MenuButton ID="btnDisableUsers" Text="禁用" OnClientClick="onDisableClick();"></f:MenuButton>
                                </Menu>
                            </f:Button>
                            <f:Button ID="btnMedia" IconAlign="Left" EnableDefaultState="false" IconFont="_Pic" Text="相册视频">
                                <Menu>
                                    <f:MenuButton Text="租户相册" OnClientClick="onAlbumClick();"></f:MenuButton>
                                    <f:MenuButton Text="农场相册" OnClientClick="onFarmAlbumClick();"></f:MenuButton>
                                    <f:MenuButton Text="系统视频" OnClientClick="onVideo1Click();"></f:MenuButton>
                                    <f:MenuButton Text="慢直播" OnClientClick="onVideo6Click();"></f:MenuButton>
                                    <f:MenuButton Text="农场监控" OnClientClick="onVideo7Click();"></f:MenuButton>
                                </Menu>
                            </f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnQrCode" IconAlign="Left" EnableDefaultState="false" IconFont="Qrcode" Text="生成二维码" OnClientClick="onQrCodeClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnConfig" IconAlign="Left" EnableDefaultState="false" IconFont="_Gear" Text="模块菜单配置" OnClientClick="onConfigClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDetails" IconAlign="Left" EnableDefaultState="false" IconFont="_List" Text="详情" OnClientClick="onDetailsClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                            <f:DropDownList ID="ddlCondition" SelectedValue="" Width="150">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="租户ID" Value="TenantID" />
                                <f:ListItem Text="租户名称" Value="TenantName" />
                            </f:DropDownList>
                            <f:TriggerBox ID="ttbSearch" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1"
                                          OnTriggerClickParameter1="@(new Parameter("actionType", "search", ParameterMode.String))"
                                          OnTriggerClickParameter2="@(new Parameter("searchText", "F.ui.ttbSearch.getValue()"))"
                                          OnTriggerClickParameter3="@(new Parameter("searchCondition", "F.ui.ddlCondition.getValue()"))">
                            </f:TriggerBox>
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    <f:RenderField HeaderText="ID" DataField="TenantID" FieldType="Int" QuickSortField="true" Width="60" TextAlign="Center" />
                    <f:RenderField HeaderText="租户名称" DataField="TenantName" Width="160" />
                    <f:RenderField HeaderText="宿主应用" DataField="WxAppID" RendererFunction="renderWxApp" Width="120" />
                    @*<f:RenderField HeaderText="城市ID" DataField="CityID" FieldType="Int" Width="80" TextAlign="Right" />*@
                    <f:RenderField HeaderText="所在城市" DataField="CityName" Width="150" RendererFunction="renderArea" />
                    <f:RenderField HeaderText="所在区县" DataField="CountyName" Width="100" Hidden="true" />
                    <f:RenderField HeaderText="Logo" DataField="LogoUrl" RendererFunction="renderImage" Width="80" TextAlign="Center" />
                    <f:RenderField HeaderText="主图" DataField="ImageUrl" RendererFunction="renderImage" Width="80" TextAlign="Center" />
                    <f:RenderField HeaderText="二维码" DataField="QrCodeUrl" RendererFunction="renderQrCode" Width="80" TextAlign="Center" />
                    <f:RenderField HeaderText="负责人" DataField="OwnerID" RendererFunction="renderOwner" Hidden="true" FieldType="Int" Width="160" TextAlign="Left" />
                    <f:RenderField HeaderText="管理员姓名" DataField="OwnerName" Hidden="true" Width="100" />
                    <f:RenderField HeaderText="管理员手机" DataField="OwnerMobile" Hidden="true" Width="100" />
        			<f:RenderField HeaderText="联系电话" DataField="Phone" Width="150" Hidden="true" />
                    <f:RenderField HeaderText="联系地址" DataField="Address" Width="150" Hidden="true" />
                    @*<f:RenderField HeaderText="会员费" DataField="MemberFee" FieldType="Double" Width="80" TextAlign="Right" />
                    <f:RenderField HeaderText="收费方式" DataField="ChargeMethod" FieldType="Int" RendererFunction="renderChargeMethod" Width="100" TextAlign="Right" />*@
                    <f:RenderField HeaderText="会员数" DataField="MemberNum" FieldType="Int" Width="80" TextAlign="Right" />
                    <f:RenderField HeaderText="点赞" DataField="LikeNum" FieldType="Int" Width="60" TextAlign="Right" />
                    <f:RenderField HeaderText="打卡" DataField="MarkNum" FieldType="Int" Width="60" TextAlign="Right" />
                    <f:RenderField HeaderText="服务分成" DataField="ServiceRate" Hidden="true" FieldType="Double" Width="90" TextAlign="Right" />
                    @*<f:RenderField HeaderText="有效期至" DataField="ExpiredDate" FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd" Width="100" TextAlign="Center" />*@
                    <f:RenderCheckField HeaderText="公开" DataField="IsPublic" RenderAsStaticField="true" Width="50" TextAlign="Center" />
                    <f:RenderCheckField HeaderText="启用" DataField="IsEnable" RenderAsStaticField="true" Width="50" TextAlign="Center" />
                    @*<f:RenderCheckField HeaderText="调试" DataField="IsDebug" RenderAsStaticField="true" Width="50" TextAlign="Center" />*@
                @*    <f:RenderField HeaderText="银行户名" DataField="BankAccountName" Width="100" Hidden="true" />
        			<f:RenderField HeaderText="银行卡号" DataField="BankAccountNo" Width="180" Hidden="true" />
        			<f:RenderField HeaderText="结算账号" DataField="BankName" RendererFunction="renderBank" MinWidth="200" />*@
                    <f:RenderField HeaderText="入驻日期" DataField="CreateTime" FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd" Width="100" TextAlign="Center" />
                    <f:RenderField HeaderText="宣传语" DataField="Title" Width="100" ExpandUnusedSpace="true" />
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" SelectedValue="@ViewBag.PageSize" OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" OnSelectedIndexChangedParameter1="@(new Parameter("actionType","changePageSize",ParameterMode.String))" OnSelectedIndexChangedFields="Panel1">
                        <Items>
                            <f:ListItem Text="10" Value="10"></f:ListItem>
                            <f:ListItem Text="20" Value="20"></f:ListItem>
                            <f:ListItem Text="30" Value="30"></f:ListItem>
                            <f:ListItem Text="50" Value="50"></f:ListItem>
                            <f:ListItem Text="100" Value="100"></f:ListItem>
                            <f:ListItem Text="200" Value="200"></f:ListItem>
                        </Items>
                    </f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>
    
    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="1000" Height="640">
        @*<Listeners>
            <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
        </Listeners>*@
    </f:Window>
}

@section script {
	<script src="~/res/js/grid.js"></script>
	<script>
        function onAddClick(event) {
            var path = "/BaseData/TenantAdd";
            F.ui.Window1.show(path, '新增租户');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/TenantEdit?id=" + selectedRow;
            F.ui.Window1.show(path, '编辑租户');
        }

        function onDeleteClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'delete',
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onEnableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要启用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要启用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'enable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onDisableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要禁用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要禁用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'disable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onSetAdminClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要操作的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/TenantSetAdmin?id=" + selectedRow;
            F.ui.Window1.show(path, '设置管理员', 400, 400);
        }

        function onQrCodeClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要操作的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/TenantQrCodeBuild?id=" + selectedRow;
            F.ui.Window1.show(path, '生成小程序二维码', 400, 400);
        }

        function onConfigClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/TenantModule?tid=" + selectedRow;
            F.ui.Window1.show(path, '应用模块配置', 1000, 750);
        }
        function onAlbumClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/Album?t=1&rid=" + selectedRow;
            F.ui.Window1.show(path, '租户相册管理', 800, 600);
        }

        function onFarmAlbumClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/Album?t=7&rid=" + selectedRow;
            F.ui.Window1.show(path, '农场相册管理', 800, 600);
        }

        function onVideo1Click(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/CMS/Video?t=1&rid=" + selectedRow;
            F.ui.Window1.show(path, '系统视频管理', 800, 600);
        }

        function onVideo6Click(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/CMS/Video?t=6&rid=" + selectedRow;
            F.ui.Window1.show(path, '慢直播视频管理', 800, 600);
        }

        function onVideo7Click(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择租户记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/CMS/Video?t=7&rid=" + selectedRow;
            F.ui.Window1.show(path, '农场监控视频管理', 800, 600);
        }

        function onDetailsClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要查看的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/TenantDetails?id=" + selectedRow;
            F.ui.Window1.show(path, '查看租户详情', 1000, 750);
        }
        function onRefreshClick() {
            var grid1 = F.ui.Grid1;
            var selectedRows = grid1.getSelectedRows();
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                actionType: 'refresh',
                selectedIDs: selectedRows
            });
        }

        function renderArea(value, params) {
            return value + "-" + params.rowData.values.CountyName;
        }

        function renderWxApp(value, params) {
            var dic = @Html.Raw(Json.Serialize(Model.WxApps));
            if (dic[value]) {
                return dic[value];
            }
            else {
                return "-";
            }
        }

        //会员收费方式：0-不收会员费，1-一次性收费，2-按年收费
        function renderChargeMethod(value, params) {
            switch (value) {
                case 0:
                    return "不收会员费";
                case 1:
                    return "一次性收费";
                case 2:
                    return "按年收费";
                default:
                    return "";
            }
        }

        //管理员信息：ID+Name
        function renderOwner(value, params) {
            if (value > 0) {
                return params.rowData.values.OwnerName + "-" + params.rowData.values.OwnerMobile;
                //return value + "-" + params.rowData.values.OwnerName + "-" + params.rowData.values.OwnerMobile;
            } else {
                return "-";
            }
        }

        //图片预览
        function renderQrCode(value, params) {
            return '<a href="javascript:;" class="imagePreview"><img style="width:45px;height:45px;margin:0,auto;" src="' + value + '"/></a>';//自定义图片按钮
        }
        function renderImage(value, params) {
            return '<a href="javascript:;" class="imagePreview"><img style="width:58px;height:45px;margin:0,auto;" src="' + value + '"/></a>';//自定义图片按钮
        }

        F.ready(function () {
            var preview = new Preview({
                imgWrap: 'Grid1' // 指定该容器里的图片点击预览
            })
        });
	</script>
    <script src="~/res/third-party/jspciyl/preview.js"></script>
}

@section head{
    <link rel="stylesheet" type="text/css" href="~/res/third-party/jspciyl/preview.css" />
    <style>
        .f-grid-cell.f-grid-cell-BankName .f-grid-cell-inner {
            white-space: normal;
            word-break: break-all;
        }
    </style>
}

